package avicit.bdp.dms.prm.Integration;

import avicit.bdp.common.base.BaseDAO;
import org.apache.commons.collections4.MapUtils;

import java.util.List;
import java.util.Map;

/**
 * 消息处理接口
 *
 * @author xugb
 * @date 2021/11/4 17:48
 */
public abstract class BaseMessageHandle {

    public void excute(String infoType, String infoAction, List<Map<String, Object>> list) {
        if (infoAction.equalsIgnoreCase("insert")) {
            excuteInsert(list);
        } else if (infoAction.equalsIgnoreCase("update")) {
            excuteUpdate(list);
        } else if (infoAction.equalsIgnoreCase("delete")) {
            excuteDelete(list);
        }
    }

    public void excuteDelete(List<Map<String, Object>> list){
        BaseDAO dao = getDAO();
        if(dao == null){
            return;
        }
        for (Map<String, Object> map : list) {
            String id = MapUtils.getString(map, "id");
            dao.deleteByPrimaryKey(id);
        }
    }

    public abstract void excuteUpdate(List<Map<String, Object>> list);

    public abstract void excuteInsert(List<Map<String, Object>> list);

    public abstract String getType();

    public abstract BaseDAO getDAO();

}
